<template>
	<view>
		<Header title="推广中心" />
		<view class="" style="height:150rpx;"></view>
		<!-- <view class="top_box" v-if="!invitationCode">
			<view style="padding-top: 77rpx;">
				暂未生成邀请码
			</view>
			<image src="@/static/tuicode.png" mode="aspectFill" class="top_img"></image>
			<view class="top_btn" @click="cread()">生成邀请码</view>
		</view> -->
		<view class="top_box">
			<view style="font-size: 57rpx;color: black;font-weight: 600;padding-top: 77rpx;">{{invitationCode}}</view>
			<view>你的邀请码</view>
			<view class="top_btn" style="margin-top: 30rpx;" @click="fuzhi">复制邀请码</view>
		</view>
		<scroll-view class="cunt_box" @scrolltolower="scrolltolower">
			<view class="cunt_boxTopflx">
				<view class="cunt_boxTopline"></view>
				<view>邀请成功记录</view>
			</view>
			<view class="" v-if="records.length>0">
				<view class="item_box" v-for="(item,i) in records">
					<view class="" style="font-size: 28rpx;color: black;font-weight: 600;">{{item.ydriverName}}({{item.phoneNumber ? '司机':'供应商'}}) </view>
					<view class="" v-if="item.phoneNumber">联系方式：{{item.phoneNumber}}</view>
					<view class="" v-if="item.companyTel">联系方式：{{item.companyTel}}</view>
					<view class="">邀请时间：{{item.createTime}}</view>
				</view>
			</view>
			<view class="" v-else style="text-align: center;margin-top: 50rpx;">
				<image src="../../../static/meiyou.png" mode="aspectFill" style="width: 250rpx;height: 250rpx;"></image>
			<view class="">暂无数据</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import Header from '@/components/header/header.vue'
	export default {
		components: {
			Header
		},
		data() {
			return {
				invitationCode: '',
				records: [],
				formdata: {
					current: 1,
					size: 10,
					invitationCode:''
				},
			}
		},
		onShow() {
			// this.code()
			this.cread()
			this.list()
		},
		methods: {
			fuzhi(){
				uni.setClipboardData({
					data:this.invitationCode,
					success() {
						uni.showToast({
							title:'复制成功',
							icon:'none'
						})
					}
				})
			},
			scrolltolower() {
				this.formdata.current++
				this.list()
			},
			async list() {
				this.formdata.invitationCode =this.invitationCode
				let res = await this.$http.driver.driverCodeList(this.formdata)
				if (res.data.code == 200) {
					if (this.formdata.current == 1) {
						this.records = res.data.data.records;
					} else {
						if (res.data.data.records.length > 0) {
							this.records = this.records.concat(res.data.data.records)
						} else {
							uni.showToast({
								title: '没有更多数据了',
								icon: 'none'
							})
							this.formdata.current = this.formdata.current - 1
						}
					}
				}
			},
			async code() {
				let res = await this.$http.driver.getDriverCode()
				if (res.data.code == 200) {
					this.invitationCode = res.data.msg
				}
			},
			async cread() {
				let res = await this.$http.driver.getIsDriverCode()
				if (res.data.code == 200) {
					this.invitationCode = res.data.data.invitationCode
					if(!this.invitationCode || this.invitationCode ==undefined){
						this.code()
					}
				}
			}
		}
	}
</script>

<style scoped>
	.item_box {
		margin-left: 35rpx;
		margin-top: 40rpx;
		font-size: 26rpx;
		color: #AFAFAF;
	}

	.cunt_box {
		width: 690rpx;
		height: 60vh;
		background-color: #fff;
		border-radius: 8rpx;
		margin-top: 30rpx;
		margin-left: 30rpx;
	}

	.cunt_boxTopflx {
		display: flex;
		align-items: center;
		font-size: 28rpx;
		color: #262626;
		padding-top: 45rpx;
	}

	.cunt_boxTopline {
		width: 4rpx;
		height: 27rpx;
		background-color: #29B0FD;
		margin-left: 35rpx;
		margin-right: 20rpx;
	}

	page {
		background-color: #F3F3F3;
	}

	.top_box {
		width: 690rpx;
		height: 340rpx;
		background-color: #fff;
		border-radius: 8rpx;
		margin-left: 30rpx;
		margin-top: 30rpx;
		font-size: 24rpx;
		color: #AFAFAF;
		text-align: center;
	}

	.top_img {
		width: 193rpx;
		height: 43rpx;
		margin-top: 30rpx;
	}

	.top_btn {
		width: 296rpx;
		height: 88rpx;
		text-align: center;
		line-height: 88rpx;
		background-color: #29B0FD;
		border-radius: 44rpx;
		color: #fff;
		font-size: 28rpx;
		margin: 0 auto;
	}
</style>